#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""  
@Project : project
@File : Subdomain.py
@Author : 飞宇
@Time : 2025/9/8 20:40  
@脚本说明 : 
"""
import threading
import warnings
import requests

warnings.filterwarnings("ignore")
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36",
}


def subdomain_scan(domain, sub):
    host1 = "http://" + sub + "." + domain
    host2 = "https://" + sub + "." + domain
    try:
        response1 = requests.get(host1, headers=headers, timeout=5)
        if response1.status_code in [200, 301, 302, 401, 403, 404]:
            print(f"[+] {sub}.{domain} 存活")
    except:
        try:
            response2 = requests.get(host2, headers=headers, timeout=5)
            if response2.status_code in [200, 301, 302, 401, 403, 404]:
                print(f"[+] {sub}.{domain} 存活")
        except:
            pass


def run_subdomain(domain):
    threads = []
    with open(file="../dict/dic.txt", mode="r", encoding="utf-8") as f:
        for sub in f:
            sub = sub.strip()
            t = threading.Thread(target=subdomain_scan, args=(domain, sub))
            t.start()
            threads.append(t)
    for t in threads:
        t.join()

# if __name__ == '__main__':
#     domain = input("请输入主域名:\n")
#     run_subdomain(domain)
